package com.tisson.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.tisson.dao.AcBuildingDAO;
import com.tisson.dao.AcDistrictDAO;
import com.tisson.dao.AcDoorDAO;
import com.tisson.dao.AcUserDAO;
import com.tisson.dao.AcRightDAO;
import com.tisson.pojo.AcRight;
import com.tisson.view.RightView;

public class PurviewBO {
	
	public List getDeptList(HttpServletRequest request){
		try{
			DepartmentBO dbo = new DepartmentBO();		
			return dbo.findAll(request);
		}
		catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
		
	}
	
	public List getDoorList(String userId){
		try{
			RightView view = new RightView();
			return view.findByUserId(userId);
		}
		catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
		
	}
	public List getStuffList(String userDepartment){
		try{
			AcUserDAO ac = new AcUserDAO();
			List stuffList = ac.findByUserDepartment(userDepartment);
			return stuffList;
			
		}
		catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
		
	}

	public void changeStateActivity(String userId,String doorId){
		try{
			AcRightDAO dao = new AcRightDAO();
			AcRight acRight = new AcRight();
			acRight.setDoorId(doorId);
			acRight.setUserId(userId);
			acRight.setState(0);
			dao.update(acRight);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void changeStateInactivity(String userId,String doorId){
		try{
			AcRightDAO dao = new AcRightDAO();
			AcRight acRight = new AcRight();
			acRight.setDoorId(doorId);
			acRight.setUserId(userId);
			acRight.setState(1);
			dao.update(acRight);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void delete(String userId,String doorId){
		try{
			AcRightDAO dao = new AcRightDAO();
			AcRight acRight = new AcRight();
			acRight.setDoorId(doorId);
			acRight.setUserId(userId);
			dao.delete(acRight);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void add(String userId,String doorId){
		try{
			AcRightDAO dao = new AcRightDAO();
			AcRight acRight = new AcRight();
			acRight.setDoorId(doorId);
			acRight.setUserId(userId);
			acRight.setState(0);
			dao.save(acRight);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public List getOptionArea(HttpServletRequest request){
		try{
			AreaBO areaBO = new AreaBO();
			return areaBO.findAll(request);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	public List getOptionDistrict(String areaId){
		try{
			AcDistrictDAO acDistrictDAO = new AcDistrictDAO();
			return acDistrictDAO.findByAreaId(areaId);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	public List getOptionBuilding(String districtId){
		try{
			AcBuildingDAO acBuildingDAO = new AcBuildingDAO();
			return acBuildingDAO.findByDistrictId(districtId);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}
	public List getOptionDoor(String buildingId){
		try{
			AcDoorDAO acDoorDAO = new AcDoorDAO();
			return acDoorDAO.findByBuildingId(buildingId);
		}catch(Exception e){
			e.printStackTrace();
			return new ArrayList();
		}
	}

}
